package com.example.farmer.Fragment.Mine;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.example.farmer.R;
import com.example.farmer.wode.AftersaleActivity;
import com.example.farmer.wode.AllordersActivity;
import com.example.farmer.wode.CarActivity;
import com.example.farmer.wode.EvalueActivity;
import com.example.farmer.wode.LikeActivity;
import com.example.farmer.wode.PayingActivity;
import com.example.farmer.wode.RecivingActivity;
import com.example.farmer.wode.SendingActivity;
import com.example.farmer.wode.SettingActivity;
import com.example.farmer.wode.ShoppingActivity;
import com.example.farmer.wode.TrackActivity;


public class MineFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // 使用布局填充器加载布局
        return inflater.inflate(R.layout.fragment_wode, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        //获取登录页面传来的id和name
        TextView per_number = view.findViewById(R.id.per_number);
        SharedPreferences sharedPreferences = getContext().getSharedPreferences("loginNumber", Context.MODE_PRIVATE);
        String userNumber = sharedPreferences.getString("userNumber" , "") ;
        per_number.setText(userNumber);

        // 获取设置按钮并设置点击事件
        ImageButton settingButton = view.findViewById(R.id.shezhi);
        settingButton.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), SettingActivity.class);
            startActivity(intent);
            // 点击设置按钮时的操作，例如打开设置界面
        });

        // 获取底部导航栏的各个按钮并设置点击事件
        ImageButton shoppingButton = view.findViewById(R.id.shopping);
        shoppingButton.setOnClickListener(v -> {
            // 点击购物车按钮时的操作
            Intent intent = new Intent(getActivity(), CarActivity.class);
            startActivity(intent);

        });

        ImageButton likeButton = view.findViewById(R.id.like);
        likeButton.setOnClickListener(v -> {
            // 点击收藏按钮时的操作
            Intent intent = new Intent(getActivity(), LikeActivity.class);
            startActivity(intent);
        });

        ImageButton trackButton = view.findViewById(R.id.track);
        trackButton.setOnClickListener(v -> {
            // 点击足迹按钮时的操作
            Intent intent = new Intent(getActivity(), TrackActivity.class);
            startActivity(intent);
        });

        // 订单相关的按钮
        TextView allOrdersText = view.findViewById(R.id.allorders);
        allOrdersText.setOnClickListener(v -> {
            // 点击"全部订单>"时的操作
            Intent intent = new Intent(getActivity(), AllordersActivity.class);
            startActivity(intent);
        });

        ImageButton payingButton = view.findViewById(R.id.paying);
        payingButton.setOnClickListener(v -> {
            // 点击待付款按钮时的操作
            Intent intent = new Intent(getActivity(), PayingActivity.class);
            startActivity(intent);
        });

        ImageButton sendingButton = view.findViewById(R.id.sending);
        sendingButton.setOnClickListener(v -> {
            // 点击待发货按钮时的操作
            Intent intent = new Intent(getActivity(), SendingActivity.class);
            startActivity(intent);
        });

        ImageButton recivingButton = view.findViewById(R.id.reciving);
        recivingButton.setOnClickListener(v -> {
            // 点击待收货按钮时的操作
            Intent intent = new Intent(getActivity(), RecivingActivity.class);
            startActivity(intent);

        });

        ImageButton evalueButton = view.findViewById(R.id.evalue);
        evalueButton.setOnClickListener(v -> {
            // 点击待评价按钮时的操作
            Intent intent = new Intent(getActivity(), EvalueActivity.class);
            startActivity(intent);
        });

        ImageButton afterSaleButton = view.findViewById(R.id.after_sale);
        afterSaleButton.setOnClickListener(v -> {
            // 点击退款/售后按钮时的操作
            Intent intent = new Intent(getActivity(), AftersaleActivity.class);
            startActivity(intent);
        });

        // 可以继续添加其他控件和事件监听器
    }
}
